package com.bw.lib_log.logger

import com.bw.lib_log.LoggerLevel
import com.bw.lib_log.LoggerStrategy

class Logger constructor(
    private val TAG:String,
    private val level: LoggerLevel,
    private val strategy: LoggerStrategy,
    private val isDebug: Boolean,
    private val path: String
){
    constructor(builder: Builder):this(
        builder.TAG,
        builder.level,
        builder.strategy,
        builder.isDebug,
        builder.path
    )
    private var logger:ILogger
    /**
     * 策略者模式
     */
    init {
        when(strategy){
            LoggerStrategy.LOG_CAT -> logger = LogCatLogger()
            LoggerStrategy.FILE -> logger = FileLogger()
            LoggerStrategy.NET -> logger = NetLogger()
        }
        logger.setTag(TAG)
        logger.setDebug(isDebug)
        logger.setLevel(level)
        logger.setSavaUrl(path)
    }

    fun v(Tag: String,log:String){
        logger.v(Tag,log)
    }
    fun d(Tag: String,log:String){
        logger.d(Tag,log)
    }
    fun i(Tag: String,log:String){
        logger.i(Tag,log)
    }
    fun w(Tag: String,log:String){
        logger.w(Tag,log)
    }
    fun e(Tag: String,log:String){
        logger.e(Tag,log)
    }


    /**
     * 构建者构建模式：多个参数的时候可以按需加载 不需要全部设置
     */
    class Builder{
        var TAG :String = ""
        var level:LoggerLevel = LoggerLevel.DEBUG
        var strategy: LoggerStrategy = LoggerStrategy.LOG_CAT
        var isDebug:Boolean = true
        var path:String = ""
        fun setTag(tag:String):Builder{
            TAG = tag
            return this
        }
        fun setLevel(level:LoggerLevel):Builder{
            this.level = level
            return this
        }
        fun setStrategy(strategy: LoggerStrategy):Builder{
            this.strategy = strategy
            return this
        }
        fun setDebug(isDebug:Boolean):Builder{
            this.isDebug = isDebug
            return this
        }
        fun setPath(path:String):Builder{
            this.path = path
            return this
        }

        fun build():Logger{
            return Logger(this)
        }
    }
}